﻿using UnityEngine;
using System.Collections;

public class Character : MonoBehaviour {
    public StarBox m_StarBox;
    public GameObject m_HPBar;
    private int m_MaxHP;
    public int CurHP { get; set; }
    public int MaxHP
    {
        get
        {
            return m_MaxHP;
        }
        set
        {
            m_MaxHP = value;
        }
    }

    public Sys_Role Data { get; set; }

    public virtual void Init(Sys_Role data)
    {
        Data = data;
        MaxHP = Data.Hp;
        CurHP = 0;
        m_HPBar.GetComponent<ImageFillProgress>().Init(MaxHP, MaxHP);
    }

    public void AddHp(float hp)
    {
        CurHP += Mathf.CeilToInt(hp);
        CurHP = CurHP > MaxHP ? MaxHP : CurHP;
        CurHP = CurHP < 0 ? 0 : CurHP;
        m_HPBar.GetComponent<ImageFillProgress>().AddPercent(hp);
    }

    public float GetDef(Damage.DamageType type) {
        string[] value = Data.Def.Split(',');
        for (int i = 0; i < value.Length; i++)
        {
            string[] defValue = value[i].Split(':');
            if ((Damage.DamageType)int.Parse(defValue[0]) == type) {
                return float.Parse(defValue[1]);
            }
        }
        return 0;
    }


    public void HurtAnim()
    {

    }
}
